/*
package org.example.service.impl;

import com.fazecast.jSerialComm.SerialPort;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.dto.OrderDTO;
import org.example.dto.PrintRequest;
import org.example.service.PrinterService;
import org.example.service.TemplateEngine;
import org.example.util.SerialPortUtil;
import org.springframework.stereotype.Service;

import javax.print.*;
import javax.print.attribute.Attribute;
import javax.print.event.PrintJobAdapter;
import javax.print.event.PrintJobEvent;

import java.io.ByteArrayOutputStream;
import java.io.IOException;


@Slf4j
@Service
@RequiredArgsConstructor
public class PrinterServiceImpl implements PrinterService {

    private final SerialPort serialPort;
    private final TemplateEngine templateEngine;
    private final SerialPortUtil serialPortUtil;

    @Override
    public void printOrder(OrderDTO order, PrintRequest printRequest) {
        for (int i = 0; i < printRequest.getCopies(); i++) {
            serialPortUtil.executeWithPort(serialPort, outputStream -> {
                templateEngine.printOrder(outputStream, order, printRequest.getCutPaper());
            });
            log.info("订单 {} 打印完成，副本 {}/{}", order.getOrderId(), i+1, printRequest.getCopies());
        }
    }

}*/
